package com.kangaroo.sparksql;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.SQLContext;

import java.util.Properties;
import java.util.regex.Pattern;

/**
 * @author liubo
 * @ClassName SparkSqlDemo
 * @Description TODO
 * @Date 2020/11/1
 * @since JDK 1.8
 */
public class SparkSqlDemo {

    private static String sparkHome = ".";

    private static String appName = "sparkTest";

    private  static String master = "local";

    private static final Pattern SPACE = Pattern.compile(" ");

    public static void main(String[] args) {
         demo1();
    }

    public static void demo1(){
        SparkConf conf = new SparkConf().setAppName(appName).setMaster(master);
        JavaSparkContext context=new  JavaSparkContext(conf);
        SQLContext sqlContext=new SQLContext(context);

        String url = "jdbc:mysql://127.0.0.1:3306/demo";
        String table="test";

        Properties p=new Properties();
        p.setProperty("user","root");
//        p.setProperty("password","iThinkDT");
        p.setProperty("driver","com.mysql.jdbc.Driver");


        Dataset jdbcDF = sqlContext.read().jdbc(url,table,p);
        jdbcDF.select("*").show();

        System.out.println("haha");
    }
}
